package cn.stylefeng.guns.modular.dms.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.dms.entity.DirectoryFile;
import cn.stylefeng.guns.modular.dms.model.params.DirectoryFileParam;
import cn.stylefeng.guns.modular.dms.service.DirectoryFileService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 文件信息控制器
 *
 * @author yzb
 * @Date 2019-11-09 09:11:36
 */
@Controller
@RequestMapping("/directoryFile")
public class DirectoryFileController extends BaseController {

    private String PREFIX = "/dms/directoryFile";

    @Autowired
    private DirectoryFileService directoryFileService;

    /**
     * 跳转到主页面
     *
     * @author yzb
     * @Date 2019-11-09
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/directoryFile.html";
    }

    /**
     * 新增页面
     *
     * @author yzb
     * @Date 2019-11-09
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/directoryFile_add.html";
    }

    /**
     * 编辑页面
     *
     * @author yzb
     * @Date 2019-11-09
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/directoryFile_edit.html";
    }

    /**
     * 新增接口
     *
     * @author yzb
     * @Date 2019-11-09
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(DirectoryFileParam directoryFileParam) {
        this.directoryFileService.add(directoryFileParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author yzb
     * @Date 2019-11-09
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(DirectoryFileParam directoryFileParam) {
        this.directoryFileService.update(directoryFileParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author yzb
     * @Date 2019-11-09
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(DirectoryFileParam directoryFileParam) {
        this.directoryFileService.delete(directoryFileParam);
        return ResponseData.success();
    }

    /**
     * 批量删除接口
     *
     * @author yzb
     * @Date 2019-11-09
     */
    @RequestMapping("/batchDelete")
    @ResponseBody
    public ResponseData batchDelete(String ids) {
        List<String> list= (List<String>) JSON.parse(ids);
        this.directoryFileService.batchDelete(list);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author yzb
     * @Date 2019-11-09
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(DirectoryFileParam directoryFileParam) {
        DirectoryFile detail = this.directoryFileService.getById(directoryFileParam.getFileId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author yzb
     * @Date 2019-11-09
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(DirectoryFileParam directoryFileParam) {
        return this.directoryFileService.findPageBySpec(directoryFileParam);
    }

}


